Search this book | Previous | Table of contents | Next

"Hello, World!"


This section illustrates the simplest of .script files, the most rudimentary form of scripting for MacHTTP.

Here is the classic demonstration program used whenever new programming languages or techniques are demonstrated. This program, "hello-world-01.script" simply returns the text "Hello, World!"

Hello-world-01.script is one line long:

return "Hello, World!"
To create this script:
  1. Launch your copy of Script Editor (or you could use any text editor)
  2. Create a new file
  3. Enter the single line above
  4. Save it as a text file within your server's directory structure making sure you give it a file name with a .script extension
To run the script you must open up a URL through your server to the saved .script file. For example, http://your.domain.edu/hello-world.script. This is true for all the scripts described here. If you don't open a URL to your scripts through your server (as opposed to using your browser's Open option from the File menu), then the server will not pass the necessary information along to your scripts and/or they will not get executed.

The most important thing about this script is not the code itself. Rather, the most important thing is the code was saved as a text file and given a .script extension. Remember your machttp.conf file? With the MacHTTP distribution, the machttp.conf file contained the following MIME type definition:

SCRIPT .SCRIPT TEXT * text/html
This definition tells MacHTTP that if a requested file ends in .script, then MacHTTP is suppose to:
  1. Load the script as an ASCII text file into RAM
  2. Prepend a number of predefined global values to the script
  3. Send the modified script to AppleScript for compilation and execution
  4. Return the output of the executed script back to the client application
Consequently, this is exactly happens with hello-world-01.script. To modify this script, try changing "Hello, World" to something like "Gosh, this is fun!" or even "the (current date) as string" and see what happens.


Search this book | Previous | Table of contents | Next

Eric last edited this page on September 26, 1995. Please feel free to send comments.